import apiConfig from '@/utils/tools/authorityApi/apiConfig'
import { getProxyPath } from '../config/proxyPath'
import { createRequest } from '../utils/request'
import { flatPidToTree } from '../utils/tools/common'
import { toTree } from '@/utils/jcore/tree'
import { addparam } from './addParam'
import { local } from '../utils/jcore/storage'
const baseURL = getProxyPath('apiC')
const request = createRequest({ baseURL })
import authorityApi from '@/utils/tools/authorityApi/index.js'
/**
 * 权限相关-陈
 */

/**获取机构下的人 */
export function getUserByOrganize(data) {
  data = addparam(data)
  return request.postJson('/sysUserApi/getUserByOrganize', data)
}
/**获取机构树 */
export async function getOrganizeTreeList() {
  const res = await request.postJson(apiConfig.API.sysOrganizeApi.getListUrl)
  if (!res) return []
  return flatPidToTree(res)
}
/**获取机构列表 */
export function getOrganizeList() {
  return request.postJson(apiConfig.API.sysOrganizeApi.getListUrl)
}
/**通过公司id获取用户 */
export function getUserListByOrganize(sysOrganizeId) {
  return request.postJson(apiConfig.API.sysUserApi.getUserByOrganize, addparam({ sysOrganizeId }))
}
/**
 * 用户管理
 */
/**获取所有用户列表 */
export function getAllUserList(data) {
  return request.postJson(apiConfig.API.sysUserApi.getOrganizeAllUser, data)
}
/**获取用户列表 */
export function getUserList(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.sysUserApi.getUserFullInfoByDutyIdAndOrganize, data)
}
/**获取用户详情 */
export function getUserById(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.sysUserApi.getbyidUser, data)
}
/**用户新增 */
export function addUser(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.sysUserApi.addUserApi, data)
}
/**用户编辑 */
export function editUser(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.sysUserApi.updatedUser, data)
}
/**用户删除 */
export function removeUser(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.sysUserApi.deletedUser, data)
}

/**
 * 供应商管理
 */
/**获取所有用户列表 */
export function getAllbsSupplierApiList(data) {
  return request.postJson(apiConfig.API.bsSupplierApi.page, data)
}

// /**获取用户详情 */
export function getbsSupplierById(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsSupplierApi.getById, data)
}
// /**供应商新增 */
export function addbsSupplier(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsSupplierApi.save, data)
}
/**供应商编辑 */
export function editbsSupplier(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsSupplierApi.update, data)
}
// /**供应商删除 */
export function deletebsSupplier(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsSupplierApi.delete, data)
}
/**
 * 优秀案例管理
 */
/**获取所有案例列表 */
export function pagebsSupplierApiList(data) {
  return request.postJson(apiConfig.API.bsCardImageApi.page, data)
}

// /**获取案例详情 */
export function getByIdbsCardImageById(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsCardImageApi.getById, data)
}
// /**案例新增 */
export function savebsCardImage(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsCardImageApi.save, data)
}
/**案例编辑 */
export function editbsCardImage(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsCardImageApi.update, data)
}
// /**案例删除 */
export function deletebsCardImage(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsCardImageApi.delete, data)
}

/**
 * 招标信息管理
 */
/**获取所有招标信息列表 */
export function bsProBiddingApiList(data) {
  return request.postJson(apiConfig.API.bsProBiddingApi.page, data)
}

// /**获取招标信息详情 */
export function bsProBiddingApigeById(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsProBiddingApi.getById, data)
}
// /**招标信息新增 */
export function savebsProBiddingApi(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsProBiddingApi.save, { ...data, creator: authorityApi.sysOverallInfo.id })
}
/**招标信息编辑 */
export function editbsProBiddingApi(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsProBiddingApi.update, { ...data, creator: authorityApi.sysOverallInfo.id })
}
// /**招标信息删除 */
export function deletebsProBiddingApi(data) {
  data = addparam(data)
  return request.postJson(apiConfig.API.bsProBiddingApi.delete, data)
}
